package com.tour.controller;


import com.tour.config.ResponseWrapper;
import com.tour.entity.Admin;
import com.tour.service.impl.AdminServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-01-21
 */
@Api(tags = "管理员")
@RestController
public class AdminController {

    @Autowired
    AdminServiceImpl adminService;

    @PostMapping("/login")
    public ResponseWrapper login(@RequestBody Admin admin){
        ResponseWrapper wrapper = adminService.login(admin);
        return wrapper;
    }
    @ApiOperation("模糊查询或查询所有用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content",value = "搜索框搜索内容"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/findAllAdmin")
    public ResponseWrapper findAllAdmin(@RequestParam(name = "content",required = false)String content,
                                        @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                        @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize){
        ResponseWrapper wrapper = adminService.findAllAdmin(content,pageNum,pageSize);
        return wrapper;
    }
    @ApiOperation("注册管理员")
    @PostMapping("/addAdmin")
    public ResponseWrapper addAdmin(@RequestBody Admin admin){
        ResponseWrapper wrapper = adminService.addAdmin(admin);
        return wrapper;
    }
    @ApiOperation("修改管理员")
    @PutMapping("/updateAdmin")
    public ResponseWrapper updateAdmin(@RequestBody Admin admin){
        ResponseWrapper wrapper = adminService.updateAdmin(admin);
        return wrapper;
    }
    @ApiOperation("删除管理员")
    @ApiImplicitParam(name = "adminId",value = "管理员id")
    @DeleteMapping("/delAdmin")
    public ResponseWrapper delAdmin(@RequestParam(name = "adminId")Integer adminId){
        ResponseWrapper wrapper = adminService.delAdmin(adminId);
        return wrapper;
    }


}

